package bagu.juc.lock;

public class CounterMain {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Runnable task = () -> {
            for (int i = 1; i <= 1000; i++) {
                System.out.println(Thread.currentThread().getName() + "第" + i + "次访问临界区");
                counter.incrementV3();
            }
        };

        Thread thread1 = new Thread(task);
        Thread thread2 = new Thread(task);

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();

        System.out.println("Final count :" + counter.getCount());

    }
}
